package acm.广度优先搜索;

import java.util.*;

public class A {
    public static int x,y,z;
    public static int[] e=new int[3];
    public static int[] s=new int[3];
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while (sc.hasNext()) {
            z=sc.nextInt();
            x=sc.nextInt();
            y= sc.nextInt();
            sc.nextLine();
            if (z==0){
                return;
            }
            boolean[][][] maze=new boolean[z][x][y];

            for (int i = 0; i < z; i++) {
                for (int j = 0; j < x; j++) {
                    String str = sc.nextLine();
                    for (int k = 0; k < str.length(); k++) {
                        char c = str.charAt(k);
                        maze[i][j][k]=c!='#';
                        if (c=='S'){
                            s[0]=i;
                            s[1]=j;
                            s[2]=k;
                        }else if (c=='E'){
                            e[0]=i;
                            e[1]=j;
                            e[2]=k;
                        }
                    }
                }
                sc.nextLine();
            }
            long res = bfs(s[0], s[1], s[2], maze);
            String resStr=res==-1?"Trapped!":"Escaped in "+res+" minute(s).";
            System.out.println(resStr);
        }
    }

    static class Node{
        int[] location=new int[3];
        int count;

        public Node(int z,int x,int y) {
            this.location[0]=z;
            this.location[1]=x;
            this.location[2]=y;
        }

        public Node(int z,int x,int y, int count) {
            this(z,x,y);
            this.count = count;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Node node = (Node) o;
            return Arrays.equals(location, node.location);
        }

        @Override
        public int hashCode() {
            return Arrays.hashCode(location);
        }
    }

    public static int bfs(int i,int j,int k,boolean[][][]maze){
        Queue<Node> queue=new LinkedList<>();
        Node curr = new Node(i, j, k);
        queue.add(curr);
        Set<Node> set=new HashSet<Node>();
//        set.add(curr);
        while (!queue.isEmpty()) {
            curr = queue.poll();
            if (set.contains(curr)){
                continue;
            }else{
                set.add(curr);
            }
            int cz = curr.location[0];
            int cx = curr.location[1];
            int cy = curr.location[2];
            maze[cz][cx][cy]=false;
            if (cz==e[0]&&cx==e[1]&&cy==e[2]){
                return curr.count;
            }
            if (cz<z-1&&maze[cz+1][cx][cy]) {
                queue.add(new Node(cz+1,cx,cy,curr.count+1));
            }
            if (cz>0&&maze[cz-1][cx][cy]) {
                queue.add(new Node(cz-1,cx,cy,curr.count+1));
            }
            if (cx<x-1&&maze[cz][cx+1][cy]) {
                queue.add(new Node(cz,cx+1,cy,curr.count+1));
            }
            if (cx>0&&maze[cz][cx-1][cy]) {
                queue.add(new Node(cz,cx-1,cy,curr.count+1));
            }
            if (cy<y-1&&maze[cz][cx][cy+1]) {
                queue.add(new Node(cz,cx,cy+1,curr.count+1));
            }
            if (cy>0&&maze[cz][cx][cy-1]) {
                queue.add(new Node(cz,cx,cy-1,curr.count+1));
            }
        }
        return -1;
    }
}

